import { Toast } from "vant";
export default {
  data() {
    return {
      msg: '测试',
      arr:[],
      x:this.$store.state.social.Pages,
      timer:null,
      n:0,
      flag:true,
      diffY:0,
      rotateDiffY:0
    }
  },
  // 生命周期 - 创建完成（访问当前this实例）
  created() {
      
  },
  // 生命周期 - 挂载完成（访问DOM元素）
  mounted() {
      
  },
  computed:{
    
  },
  watch:{
    x:function(){
      this.$nextTick(()=>{
        Toast.success('加载成功');
        clearInterval(this.timer)
        this.timer=null
        this.n=0
      })
    },
    n(){
      if(this.n>=8){
        Toast.fail('加载超时');
        clearInterval(this.timer)
        this.timer=null
        this.n=0
      }
    }
  },
  // Vue方法定义
  methods: {
    touchstart(e) {
        let end={};
        let start = {};
        
        console.log(window.screen.height)
        start = {
          x: e.touches[0].clientX,
          y: e.touches[0].clientY,
        };
        this.$refs["neiceng"].style.transition=''
        this.$refs["neiceng"].addEventListener('touchmove', (e) => {
          end = {
            x: e.touches[0].clientX,
            y: e.touches[0].clientY,
          };
          //判断方向
          if (Math.abs(end.x - start.x) > Math.abs(end.y - start.y)) {
            this.flag = false;
          } else {
            this.flag = true;
          }
          this.rotateDiffY=end.y-start.y
          this.$refs['loding'].style.transform=`rotate(${this.rotateDiffY*3}deg)`
          if (this.$refs["waiceng"].scrollTop === 0 && this.flag) {
            if(this.arr.length<=1){
              this.arr.push(e.touches[0].clientY)
            }
            
            this.diffY = end.y - this.arr[0]; 
            // console.log(this.diffY)
            //加载动画
            
            
            this.$refs["neiceng"].style.transform = `translateY(${this.diffY * 0.4}px)`;
            
            
            
          }
          if(window.screen.height<=1366&&window.screen.height>812){
            if(this.$refs['waiceng'].scrollHeight-this.$refs['waiceng'].scrollTop<=1150&& this.flag){
              if(this.arr.length<=1){
                this.arr.push(e.touches[0].clientY)
              }
              end = {
                y: e.touches[0].clientY,
              };
              this.diffY = end.y - this.arr[0]; 
              
              if(Math.abs(this.diffY)<200){
                this.$refs["neiceng"].style.transform = `translateY(${this.diffY * 0.4}px)`;
              }
            }
          }else{
            if(this.$refs['waiceng'].scrollHeight-this.$refs['waiceng'].scrollTop<=661&& this.flag){
              // console.log('到底了')
              if(this.arr.length<=1){
                this.arr.push(e.touches[0].clientY)
              }
              end = {
                y: e.touches[0].clientY,
              };
              this.diffY = end.y - this.arr[0]; 
              
              if(Math.abs(this.diffY)<200){
                this.$refs["neiceng"].style.transform = `translateY(${this.diffY * 0.4}px)`;
              }
            }
          }
          
        });
      },
      
  }
}
